package cn.tedu.bootsy11.controller;

import cn.tedu.bootsy11.entity.User;
import cn.tedu.bootsy11.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserControlle {
    @Autowired
    UserMapper mapper;

    @RequestMapping("/reg")
    public int reg(@RequestBody User user){
       User u=mapper.selectByUsername(user.getUsername());
       if (u!=null){
           return 0;
       }
       mapper.insert(user);
       return 1;
    }

    @RequestMapping("/login")
    public int login(@RequestBody User user) {
        User u = mapper.selectByUsername(user.getUsername());
        System.out.println(1);
        if (u!= null) {
            if (user.getPassword().equals(u.getPassword())) {
                return 1;
            }
            return 3;
        }
        return 2;
    }
}
